include $(PROJECT_BASE)/zsystem/make/os.mk

ifneq ($(OS),Windows_NT)
  SHELL = /bin/sh
endif

ifneq ($(OS),UNIX_SV)
   MAKE = gmake
   ifeq ($(OS),Windows_NT)
   	MAKE = make
   endif
else
   MAKE = make
endif


include $(PROJECT_BASE)/zsystem/make/common.mk
mall: all
include $(PROJECT_BASE)/zsystem/make/largelib.mk

LIBSSUBDIRS = $(SRCB_LIBSSUBDIRS)

ifneq ($(noapp),)
	APPSSUBDIRS = 	
else
	APPSSUBDIRS = $(SRCB_APPSSUBDIRS)
endif

.SUFFIXES:

ifneq ($(supp),)	
  LIBSSUBDIRS = $(SUPP_LIBSUBDIRS) $(SRCB_LIBSSUBDIRS)
  APPSSUBDIRS = $(SUPP_APPSUBDIRS) $(SRCB_APPSSUBDIRS)
endif

ALL = 
ifneq ($(words $(LIBSSUBDIRS)),0)
	ALL += libs
endif
ifneq ($(words $(APPSSUBDIRS)),0)
	ALL += apps
endif

ifneq ($(LARGELIB),"")
   ALL += $(LARGELIB)
endif

all: $(ALL)

ifeq ($(SHELL_TYPE),dos)
libs: 
	echo Compiling sub-directories: $(LIBSSUBDIRS)
	FOR %s IN ($(LIBSSUBDIRS)) DO  ($(MAKE) -C %s) || EXIT 1

apps: 
	FOR %s IN ($(APPSSUBDIRS)) DO ($(MAKE) -C %s) || EXIT 1

rm: 
	FOR %s IN ($(LIBSSUBDIRS) $(APPSSUBDIRS)) DO ($(MAKE) -C %s rm) || EXIT 1)

rmt: 
	FOR %s IN ($(LIBSSUBDIRS) $(APPSSUBDIRS)) DO ($(MAKE) -C %s rmt) || EXIT 1)

else
libs: 
	echo Compiling sub-directories: $(LIBSSUBDIRS)
	for subdir in $(LIBSSUBDIRS); do \
	  echo making $@ in $$subdir; \
	  ($(MAKE) -C $$subdir) || exit 1; \
	done

apps: 
	for subdir in $(APPSSUBDIRS); do \
	  echo making $@ in $$subdir; \
	  (cd $$subdir && $(MAKE) ) || exit 1; \
	done


rm: 
	for subdir in $(LIBSSUBDIRS) $(APPSSUBDIRS); do \
	  echo making rm in $$subdir; \
	  (cd $$subdir && $(MAKE) rm) || exit 1; \
	done

rmt: 
	for subdir in $(LIBSSUBDIRS) $(APPSSUBDIRS); do \
	  echo making rm in $$subdir; \
	  (cd $$subdir && $(MAKE) rmt) || exit 1; \
	done

endif

rmall:
	$(RM) -f $(objdir)/*.o
	$(RM) -f $(objdir)/*.d
	$(RM) -f $(libdir)/*.a
	$(RM) -f $(libsubdir)/*.a
	$(RM) -f $(bindir)/*


check:
installcheck:

$(PROGS):
	cd application && $(MAKE) $@

app:
	cd application && rm -f testApp
	cd application && rm -f dfTest
	cd application && $(MAKE) testApp

mostlyclean: mostlyclean-recursive mostlyclean-local

clean: clean-recursive clean-local

distclean: distclean-recursive distclean-local
	rm config.status

realclean: realclean-recursive realclean-local
	rm config.status

TAGS clean-recursive distclean-recursive \
	    mostlyclean-recursive realclean-recursive:
	for subdir in $(SUBDIRS); do \
	  target=`echo $@|sed 's/-recursive//'`; \
	  echo making $$target in $$subdir; \
	  (cd $$subdir && $(MAKE) $$target) || exit 1; \
	done

mostlyclean-local:

clean-local: mostlyclean-local

distclean-local: clean-local
	rm -f Makefile config.cache config.h config.log stamp-h distname

realclean-local: distclean-local

distname: src/version.c
	echo fileutils-`sed -e '/version_string/!d' \
	    -e 's/[^0-9.]*\([0-9.a-z]*\).*/\1/' -e q src/version.c` > $@-tmp
	mv $@-tmp $@

ifeq ($(SHELL_TYPE),dos)
	MKDIR_COMMAND = IF NOT EXIST "$(distdir)" MKDIR "$(distdir)"
else
	MKDIR_COMMAND = mkdir $(distdir)
endif

distdir = `cat distname`
dist: $(DISTFILES) distname
	rm -rf $(distdir)
	$(MKDIR_COMMAND)
	for file in $(DISTFILES); do \
	  ln $$file $(distdir) \
	    || { echo copying $$file instead; cp -p $$file $(distdir);}; \
	done
	for subdir in $(SUBDIRS); do \
	  mkdir $(distdir)/$$subdir || exit 1; \
	  (cd $$subdir && $(MAKE) $@) || exit 1; \
	done
	tar --gzip -chvf $(distdir).tar.gz $(distdir)
	rm -rf $(distdir) distname

# For the justification of the following Makefile rules, see node
# `Automatic Remaking' in GNU Autoconf documentation.

#Makefile: config.status Makefile.in
#	CONFIG_FILES=$@ CONFIG_HEADERS= ./config.status

config.h: stamp-h
stamp-h: config.status $(srcdir)/config.h.in
	CONFIG_FILES= CONFIG_HEADERS=config.h ./config.status

# Use echo instead of date to avoid spurious conflicts for
# people who use CVS, since stamp-h.in is distributed.
	echo > $(srcdir)/$@

version:
	@echo Version:$(VERSION) By $(AUTHOR)

run:
	@echo Only application can run.

valgrind:
	@echo Only application can run.

# Tell versions [3.59,3.63) of GNU make not to export all variables.
# Otherwise a system limit (for SysV at least) may be exceeded.
.NOEXPORT:


